home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / T U R B O Language / Turbo Pascal V7.0 / TVDEBUG.ZIP / CMDNAMER.PAS next >
Encoding:
Pascal/Delphi Source File  |  1992-10-30  |  3.7 KB  |  136 lines

  1. unit CmdNamer;
  2.  
  3. interface
  4.  
  5. { Registers all the built in Turbo Vision commands with the command
  6.   namer }
  7. procedure BuiltInCommandNames;
  8.  
  9. { Returns the name of the given command }
  10. function CommandName(Command: Word): String;
  11.  
  12. { Registers the given command with the command namer }
  13. procedure NameCommand(Command: Word; const Name: String);
  14.  
  15. implementation
  16.  
  17. uses Strings, Objects, Views, App, Dialogs;
  18.  
  19. { Command Database }
  20.  
  21. type
  22.   PCommandItem = ^TCommandItem;
  23.   TCommandItem = record
  24.     Command: Word;
  25.     Name: PString;
  26.   end;
  27.  
  28.   TCommandCollection = object(TSortedCollection)
  29.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  30.     procedure FreeItem(P: Pointer); virtual;
  31.     function KeyOf(P: Pointer): Pointer; virtual;
  32.   end;
  33.  
  34. function TCommandCollection.Compare(Key1, Key2: Pointer): Integer;
  35. begin
  36.   Compare := LongInt(Key1) - LongInt(Key2);
  37. end;
  38.  
  39. procedure TCommandCollection.FreeItem(P: Pointer);
  40. begin
  41.   DisposeStr(PCommandItem(P)^.Name);
  42.   Dispose(PCommandItem(P));
  43. end; 
  44.  
  45. function TCommandCollection.KeyOf(P: Pointer): Pointer;
  46. begin
  47.   KeyOf := Pointer(PCommandItem(P)^.Command);
  48. end;
  49.  
  50. var
  51.   CommandDB: TCommandCollection;
  52.  
  53. { Default commands }
  54.  
  55. type
  56.   TDefName = record
  57.     Name: PChar;
  58.     Command: Word;
  59.   end;
  60.  
  61. const
  62.   DefCommands: array[0..36] of TDefName = (
  63.     (Name: 'cmValid'; Command: cmValid),
  64.     (Name: 'cmQuit'; Command: cmQuit),
  65.     (Name: 'cmError'; Command: cmError),
  66.     (Name: 'cmMenu'; Command: cmMenu),
  67.     (Name: 'cmClose'; Command: cmClose),
  68.     (Name: 'cmZoom'; Command: cmZoom),
  69.     (Name: 'cmResize'; Command: cmResize),
  70.     (Name: 'cmNext'; Command: cmNext),
  71.     (Name: 'cmPrev'; Command: cmPrev),
  72.     (Name: 'cmHelp'; Command: cmHelp),
  73.     (Name: 'cmOK'; Command: cmOK),
  74.     (Name: 'cmCancel'; Command: cmCancel),
  75.     (Name: 'cmYes'; Command: cmYes),
  76.     (Name: 'cmNo'; Command: cmNo),
  77.     (Name: 'cmDefault'; Command: cmDefault),
  78.     (Name: 'cmCut'; Command: cmCut),
  79.     (Name: 'cmCopy'; Command: cmCopy),
  80.     (Name: 'cmPaste'; Command: cmPaste),
  81.     (Name: 'cmUndo'; Command: cmUndo),
  82.     (Name: 'cmClear'; Command: cmClear),
  83.     (Name: 'cmTile'; Command: cmTile),
  84.     (Name: 'cmCascade'; Command: cmCascade),
  85.     (Name: 'cmNew'; Command: cmNew),
  86.     (Name: 'cmOpen'; Command: cmOpen),
  87.     (Name: 'cmSave'; Command: cmSave),
  88.     (Name: 'cmSaveAs'; Command: cmSaveAs),
  89.     (Name: 'cmSaveAll'; Command: cmSaveAll),
  90.     (Name: 'cmChangeDir'; Command: cmChangeDir),
  91.     (Name: 'cmDosShell'; Command: cmDosShell),
  92.     (Name: 'cmCloseAll'; Command: cmCloseAll),
  93.     (Name: 'cmReceivedFocus'; Command: cmReceivedFocus),
  94.     (Name: 'cmReleasedFocus'; Command: cmReleasedFocus),
  95.     (Name: 'cmCommandSetChanged'; Command: cmCommandSetChanged),
  96.     (Name: 'cmScrollBarChanged'; Command: cmScrollBarChanged),
  97.     (Name: 'cmScrollBarClicked'; Command: cmScrollBarClicked),
  98.     (Name: 'cmSelectWindowNum'; Command: cmSelectWindowNum),
  99.     (Name: 'cmListItemSelected'; Command: cmListItemSelected));
  100.  
  101.  
  102. procedure BuiltInCommandNames;
  103. var
  104.   I: Integer;
  105. begin
  106.   for I := Low(DefCommands) to High(DefCommands) do
  107.     NameCommand(DefCommands[I].Command, StrPas(DefCommands[I].Name));
  108. end;
  109.     
  110. procedure NameCommand(Command: Word; const Name: String);
  111. var
  112.   P: PCommandItem;
  113. begin
  114.   New(P);
  115.   P^.Command := Command;
  116.   P^.Name := NewStr(Name);
  117.   CommandDB.Insert(P);
  118. end; 
  119.  
  120. function CommandName(Command: Word): String;
  121. var
  122.   I: Integer;
  123.   S: String;
  124. begin
  125.   if CommandDB.Search(Pointer(Command), I) then
  126.     CommandName := PCommandItem(CommandDB.At(I))^.Name^
  127.   else
  128.   begin
  129.     Str(Command, S);
  130.     CommandName := 'unknown ' + S;
  131.   end;
  132. end;
  133.  
  134. begin
  135.   CommandDB.Init(High(DefCommands) + 1, 10);
  136. end.